unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls;

const
  N=10;

type
  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    ScrollBar1: TScrollBar;
    Timer1: TTimer;
    procedure ScrollBar1Change(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  i, j : integer;
  turn : array of integer;
  arr : array of TPanel;

implementation

{$R *.dfm}

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
  Timer1.Interval:=ScrollBar1.Position;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
for j:=0 to N-1 do
  begin
  arr[j]:=TPanel.Create(Form1);
  arr[j].Height:=60;
  arr[j].Width:=60;
  arr[j].Left:=50+120*j;
  arr[j].Top:=30;
  arr[j].Parent:=Form1;
  end;


 Timer1.Enabled:=True;
  i:=0;
  for i:=0 to N do
    arr[i].Caption:=inttostr(turn[i]);
  i:=0;
  j:=0;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  tmp : integer;
begin
for i:=0 to N-1 do
begin
  if (turn[i]>turn[i+1]) then
  begin
    tmp:=turn[i];
    turn[i]:=turn[i+1];
    turn[i+1]:=tmp;
  end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  setlength(arr,N);
  setlength(turn,N);
  randomize;
  for i:=0 to N-1 do
  begin
    turn[i]:=random(20);
  end;

end;






end.

